import { ref, computed } from "vue";
import { defineStore } from "pinia";
import { time, timeD } from "../components/Method";

import dayjs from "dayjs";
export const useCounterStore = defineStore("counter", () => {
  // 地图点击相应内容

 const inpVal =ref('')
  const price =ref()

  function getNum(a, b) {
    let max = Math.max(a, b);
    let min = Math.min(a, b);

    return parseInt(Math.random() * (max - min + 1) + min);
  }
  // 正计时
  function times(val) {
    const day = ref(time(val));
    setInterval(() => {
      day.value = time(val);
    }, 1000);
    return day;
  }
  // 倒计时
  function timeDao(val = "2022-12-14 16:03:11") {
    const day1 = ref();
    let Time = dayjs(val).valueOf();
    let TimeDay = Time + 60 * 60 * 1000;
    setInterval(() => {
      let TimeQWE = TimeDay - new Date().getTime();
      if (TimeQWE <= 0) {
        // console.log("已过期");
        day1.value = "已过期";
      } else {
        day1.value = timeD(TimeQWE);
      }
    }, 1000);
    return day1;
  }
  return { getNum, times, timeDao , inpVal ,price};
});
